﻿using System;
using System.Data;
using System.Text;
using System.Web.UI.HtmlControls;

namespace LKCMS.Web
{
    public partial class SmallType : System.Web.UI.Page
    {
        public int Id;
        protected void Page_Load(object sender, EventArgs e)
        {
               if (!int.TryParse(Request.Params["id"] as string, out this.Id))
                {
                    JscriptMsg(300, 120, "错误提示", "<div style=\" padding:5px 5px 5px 5px; text-align:left;line-height:30px;\"><b>亲爱访友：</b><br/>&nbsp;&nbsp&nbsp;&nbsp;<span style=\"color:#FBF204;\">您要打开的信息不存在或参数不正确。<span/><br/></div><div style=\"text-align:center;\"><a href=\"Index.aspx\">跳转到首页</a></div>");
                    return;
                }
            if (!Page.IsPostBack)
            {
                Bind(this.Id);
            }
        }
        private void BindMeta(string classname)
        {
            LKCMS.Model.WebSet webset = new LKCMS.BLL.WebSet().loadConfig(LKCMS.Common.Utils.GetXmlMapPath("Configpath"));

            Page.Title = classname + "_" + webset.WebKeywords;


            //Encode/Content type
            HtmlMeta encode = new HtmlMeta();
            encode.HttpEquiv = "Content-Type";
            encode.Content = "text/html; charset=utf-8";
            Page.Header.Controls.Add(encode);

            //Language
            HtmlMeta lang = new HtmlMeta();
            lang.HttpEquiv = "Content-Language";
            lang.Content = "zh-cn";
            Page.Header.Controls.Add(lang);

            //Description
            HtmlMeta desc = new HtmlMeta();
            desc.Name = "Description";
            desc.Content = webset.WebDescription;
            Page.Header.Controls.Add(desc);

            //Keyword
            HtmlMeta keywords = new HtmlMeta();
            keywords.Name = "keywords";
            keywords.Content = webset.WebKeywords;
            Page.Header.Controls.Add(keywords);

        }
        /// <summary>
        /// 遮罩提示窗口
        /// </summary>
        /// <param name="w">宽度</param>
        /// <param name="h">高度</param>
        /// <param name="msgtitle">窗口标题</param>
        /// <param name="msgbox">提示文字</param>
        /// <param name="url">返回地址</param>
        /// <param name="msgcss">CSS样式</param>
        private void JscriptMsg(int w, int h, string msgtitle, string msgbox)
        {
            string msbox = "";
            msbox += "<script src=\"Js/jsmsg.js\" type=\"text/javascript\"></script>\n";
            msbox += "<script type=\"text/javascript\">\n";

            msbox += "alertWin('" + msgtitle + "','" + msgbox + "'," + w + "," + h + ");";
            msbox += "</script>";
            this.Literal2.Text = msbox;
            //  Msg.Text = msbox;
            // Response.End();
        }

        private void Bind(int id)
        {
            StringBuilder sb = new StringBuilder();
            StringBuilder sb1 = new StringBuilder();
            LKCMS.BLL.Channel bll = new LKCMS.BLL.Channel();
            LKCMS.BLL.Pictures pll = new LKCMS.BLL.Pictures();
            LKCMS.BLL.Article all = new LKCMS.BLL.Article();
            LKCMS.Model.Channel model = bll.GetModel(id);

            string typename = model.Title;
            BindMeta(typename);
            lbtitle.Text = model.Title;
            DataTable dt = bll.GetListNew(" ParentId=" + id);

            string urladd = string.Empty;
            DataTable dtzx = new DataTable();
            DataTable dtrd = new DataTable();
            if(dt.Rows.Count==0)
            {

                 GetData(model.Id,model.KindId, 0);
                 string s = bll.GetChannels(id).ToString();
                 if (s != "")
                 {
                     switch (model.KindId)
                     {
                         case 0:
                             dtzx = all.GetList(15, " ClassId in (" + s + ")", " AddTime desc,Click desc").Tables[0];
                             dtrd = all.GetList(15, " ClassId in (" + s + ")", " Click desc,AddTime desc").Tables[0];
                             urladd = "DetailWB.aspx";
                             break;
                         case 1:
                             dtzx = pll.GetList(15, " ClassId in (" + s + ")", " AddTime desc,Click desc").Tables[0];
                             dtrd = pll.GetList(15, " ClassId in (" + s + ")", " Click desc,AddTime desc").Tables[0];
                             urladd = "DetailTW.aspx";
                             break;
                         case -1:
                             break;
                         default:
                             break;
                     }
                 }

                 if (urladd != string.Empty)
                 {





                     //最近更新
                     if (dtzx.Rows.Count > 0)
                     {
                         sb.Append("<div class=\"right_block\">");
                         sb.Append("<div class=\"right_block_title\">");
                         sb.Append("<div class=\"left_block_title_text\"><strong>" + typename + "</strong>最近更新</div>");
                         sb.Append("</div>");
                         sb.Append("<div class=\"right_block_content\">");
                         sb.Append("<ul>");



                         foreach (DataRow dr1 in dtzx.Rows)
                         {
                             string title=dr1["Title"].ToString();
                             if (title.Length > 18)
                             {
                                 title = title.Substring(0, 18) + "...";
                             }
                             sb.Append("<li>. <a href=\"/" + urladd + "?id=" + dr1["ID"].ToString() + "\" title=\"" + dr1["Title"].ToString() + "/ " + dr1["AddTime"].ToString() + "\" target=\"_blank\">" + title + "</a></li>");
                         }
                         sb.Append(" </ul>");
                         sb.Append("</div>");
                         sb.Append("</div>  ");
                     }

                     //最热
                     if (dtrd.Rows.Count > 0)
                     {
                         sb.Append("<div class=\"right_block\">");
                         sb.Append("<div class=\"right_block_title\">");
                         sb.Append("<div class=\"left_block_title_text\"><strong>" + typename + "</strong>热点</div>");
                         sb.Append("</div>");
                         sb.Append("<div class=\"right_block_content\">");
                         sb.Append("<ul>");


                         foreach (DataRow dr2 in dtrd.Rows)
                         {
                             string title1 = dr2["Title"].ToString();
                             if (title1.Length > 18)
                             {
                                 title1 = title1.Substring(0, 18) + "...";
                             }
                             sb.Append("<li>. <a href=\"/" + urladd + "?id=" + dr2["ID"].ToString() + "\" title=\"" + dr2["Title"].ToString() + "/ " + dr2["Click"].ToString() + " Hits\" target=\"_blank\">" + title1 + "</a></li>");
                         }

                         sb.Append(" </ul>");
                         sb.Append("</div>");
                         sb.Append("</div>  ");
                     }
                 }

                this.LiteraClassType.Text = sb.ToString();
                   
                    int nor=bll.GetModel(id).ParentId;

                    int big = bll.GetModel(nor).ParentId;
                    sb1.Append(" <a href=\"Index.aspx\">网站首页</a> > ");
                    sb1.Append(" <a href=\"BigType.aspx?id=" + big + "\">" + bll.GetChannelTitle(big) + "</a>");
                    sb1.Append(" > <a href=\"NormalType.aspx?id="+nor+"\">"+bll.GetChannelTitle(nor)+"</a> >  ");
                    sb1.Append(" <strong>"+model.Title+"</strong> ");
                   // sb1.Append("  ");



                   



 

 

                this.Literaldh.Text=sb1.ToString();

            

            }

        }
        private void GetData(int id,int kid,int current)
        {
            DataTable dt = new DataTable();
             LKCMS.BLL.Pictures pll = new LKCMS.BLL.Pictures();
            LKCMS.BLL.Article all = new LKCMS.BLL.Article();
             StringBuilder sb1 = new StringBuilder();
             int totalcount = 0;
             int pagesize = 0;
            switch (kid)
            {
                case 0:
                    dt = all.GetPageList(8, current, " ClassId=" + id, "AddTime desc").Tables[0];
                    totalcount = all.GetList(" ClassId=" + kid).Tables[0].Rows.Count;
                    pagesize =20;
                    sb1.Append("<div class=\"type_text_case2\">");
                            sb1.Append("<ul>");
                            foreach (DataRow dr12 in dt.Rows)
                            {

                                sb1.Append("<li><a href=\"DetailWB.aspx?id=" + dr12["ID"].ToString() + "\" title=\"" + dr12["Title"].ToString() + "\" target=\"_blank\">" + dr12["Title"].ToString() + "</a> <span class=whitebot> - " + Convert.ToDateTime(dr12["AddTime"]).ToString("MM/dd/yyyy") + "</span></li> ");
                            }
                            sb1.Append("</ul>");
                            sb1.Append("</div>");
                    break;
                case 1:
                    dt = pll.GetPageList(12, current, " ClassId=" + id, "SortId asc,AddTime desc").Tables[0];
                    totalcount = pll.GetList(" ClassId=" + kid).Tables[0].Rows.Count;
                    pagesize =32;
                    sb1.Append("<div id=\"three_pics\">");
                            sb1.Append("<ul>");
                            foreach (DataRow dr11 in dt.Rows)
                            {

                                sb1.Append("<li><a title=\"RMB " + Convert.ToDecimal(dr11["Price"]).ToString("f2") + "元/人 -" + dr11["Title"].ToString() + "\" href=\"DetailTW.aspx?id=" + dr11["ID"].ToString() + "\"><img width=\"146\" height=\"71\" alt=\"" + dr11["Title"].ToString() + "\" src=\"" + dr11["ImgUrl"].ToString() + "\" border=\"0\"><div>" + dr11["Title"].ToString() + "</div></a><div class=\"pic_price\">RMB " + Convert.ToDecimal(dr11["Price"]).ToString("f2") + "元/人</div></li> ");
                            }
                            sb1.Append("</ul>");
                            sb1.Append("</div>");
                    break;
                case -1:
                    break;
                default:
                    break;
            }

            this.AspNetPager1.RecordCount = totalcount;
            this.AspNetPager1.PageSize = pagesize;
              this.LiteralContent.Text = sb1.ToString();
        }


        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
             LKCMS.BLL.Channel bll = new LKCMS.BLL.Channel();
            LKCMS.Model.Channel model = bll.GetModel(Id);
            GetData(model.Id,model.KindId, this.AspNetPager1.CurrentPageIndex);
        }
    }
}
